import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;


public class Processor {

	
	private ArrayList<Register> gpRegisters;
	private ALU alu;
	private ControlUnit ctrlUnit;
	private InstructionSet instrSet;
	private int programCounter;
	private String accumulator;
	private String instructionRegister;
	private String statusRegister;
	
	private MainMemory memory;
	private ArrayList<String> addresses;
	
	
	public Processor(){
		
		gpRegisters = new ArrayList<Register>();
		addresses = new ArrayList<String>();
		declareGPRegisters(gpRegisters);	//create 8 general purpose registers
		alu = new ALU();
		ctrlUnit = new ControlUnit();
		instrSet = new InstructionSet();
		
		programCounter = 0; //PC starts at 0
	}
	
	
	public void initProcessor(){
		
		while(programCounter <= memory.memorySize() ){
			
			
			
			
			
			
		}
		
		
		
	}
	
	
	public int findAddressingMode(String instruction){
		
		return 0;
	}
	
	
	private void declareGPRegisters(ArrayList<Register> registers){
		
		for(int i = 8; i < 8;i++){
			
			registers.add(new Register());
		}
		
	}
	
	public boolean readFile(){
		
		try{
			  // Open the file that is the first 
			  // command line parameter
			  FileInputStream fstream = new FileInputStream("test.txt");
			  // Get the object of DataInputStream
			  DataInputStream in = new DataInputStream(fstream);
			  BufferedReader br = new BufferedReader(new InputStreamReader(in));
			  String strLine;
			  //Read File Line By Line
			  
			  
			  while ((strLine = br.readLine()) != null)   {
			  // Insert content to memory
				  memory.insertData(strLine);
				  byte[] addr = Tools.hexStringToByteArray(strLine);
				  String sAddr = Tools.byteToString(addr);
				  addresses.add(sAddr);
			  	  
			  }
			  //Close the input stream
			  in.close();
			  
			  return true;
			    }catch (Exception e){//Catch exception if any
			  System.err.println("Error: " + e.getMessage());
			 }
		
		return false;
	}
	
	
}
